﻿using System.Collections.Generic;
using System.Data;
using Smatime.Web.DAO.SmatimeDatasetTableAdapters;
using Smatime.Web.Models;

namespace Smatime.Web.DAO
{
    public class UserStoreRepository :
        BaseRepository<CompanyStore, SmatimeDataset.StoreOfUserDataTable, StoreOfUserTableAdapter>
    {
        /// <summary>
        ///     Get all stores belong to a User by the User id number.
        /// </summary>
        /// <returns></returns>
        public IEnumerable<CompanyStore> GetStoresByUserId(long id)
        {
            using (var adapter = new StoreOfUserTableAdapter())
            {
                using (var table = adapter.GetDataByUserId(id))
                {
                    var results = new List<CompanyStore>();
                    foreach (DataRow row in table.Rows)
                    {
                        var storeOfStaff = new CompanyStore();
                        storeOfStaff.FromDataRow(row);
                        results.Add(storeOfStaff);
                    }
                    return results;
                }
            }
        }
    }
}